#!/usr/bin/env python

# Imports:
# -------
import wx
from wx.lib.mixins.rubberband import RubberBand

# --------------------------
class LabelerPanel(wx.Panel):
# --------------------------
	# ------------------------
	def __init__(self, parent):
	# ------------------------
		wx.Panel.__init__(self, parent=parent)

		# Create the sizer
		self.sizer = wx.BoxSizer(wx.VERTICAL)
		self.SetSizer(self.sizer)

		# Load the questionmark
		self.questionMark = wx.Image('resources/question_mark.png', wx.BITMAP_TYPE_PNG)
		self.questionMark = wx.BitmapFromImage(self.questionMark)
		self.image = wx.StaticBitmap(self, wx.ID_ANY, self.questionMark)
		self.sizer.Add(self.image, 3)
		
		# Create ther rubber bander
		self.rubberBand = RubberBand(drawingSurface=self.image)
		self.rubberBand.reset(aspectRatio=1)
		
		# Name input
		self.nameInputSizer = wx.BoxSizer(wx.HORIZONTAL)
		self.nameInputButton = wx.Button(self, wx.ID_ANY, 'Ok')
		self.nameInputSizer.Add(self.nameInputButton)
		self.sizer.Add(self.nameInputSizer, 0, wx.CENTER)

		# Create the left/right buttons
		self.leftRightSizer = wx.BoxSizer(wx.HORIZONTAL)
		self.leftButton = wx.Button(self, wx.ID_ANY, '<--')
		self.leftButton.Disable()
		self.leftRightSizer.Add(self.leftButton, 0, wx.CENTER)
		self.frameText = wx.StaticText(self, label='  (##/##)  ')
		self.leftRightSizer.Add(self.frameText, 0, wx.CENTER)
		self.rightButton = wx.Button(self, wx.ID_ANY, '-->')
		self.rightButton.Disable()
		self.leftRightSizer.Add(self.rightButton, 0, wx.CENTER)
		self.sizer.Add(self.leftRightSizer, 0, wx.CENTER)

		# Add the image topic listbox
		self.listBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
		self.imageTopicLBSizer= wx.BoxSizer(wx.VERTICAL)
		imageTopicLBLabel = wx.StaticText(self, label='Image topics')
		self.imageTopicLBSizer.Add(imageTopicLBLabel, 0, wx.CENTER)
		self.imageTopicLB = wx.ListBox(self, -1, (-1,-1), (-1,-1), [], wx.LB_SINGLE)
		self.imageTopicLBSizer.Add(self.imageTopicLB, 1, wx.EXPAND)
		self.listBoxSizer.Add(self.imageTopicLBSizer, 1, wx.EXPAND)
	
		# Add the annotation topic listbox
		self.annotationTopicLBSizer= wx.BoxSizer(wx.VERTICAL)
		annotationTopicLBLabel = wx.StaticText(self, label='Annotation topics')
		self.annotationTopicLBSizer.Add(annotationTopicLBLabel, 0, wx.CENTER)
		self.annotationTopicLB = wx.ListBox(self, -1, (-1,-1), (-1,-1), [], wx.LB_SINGLE)
		self.annotationTopicLBSizer.Add(self.annotationTopicLB, 1, wx.EXPAND)
		self.listBoxSizer.Add(self.annotationTopicLBSizer, 1, wx.EXPAND)
	
		# Annotation information
		self.annotations = [] 
		#self.Bind(wx.EVT_PAINT, self.onPaint)

		self.sizer.Add(self.listBoxSizer, 1, wx.EXPAND)

	# ----------------------------
	def displayImage(self, image):
	# ---------------------------
		self.image.SetBitmap(image)
		self.Layout()

	# ----------------------------------
	def displayImageTopics(self, topics):
	# ----------------------------------
		self.imageTopics = topics

		self.imageTopicLB.Clear()
		self.imageTopicLB.SetItems(topics)

	# ---------------------------------------
	def displayAnnotationTopics(self, topics):
	# ---------------------------------------
		self.annotationTopics = topics

		self.annotationTopicLB.Clear()
		self.annotationTopicLB.SetItems(topics)

	# -------------------------------
	def selectImageTopic(self, topic):
	# -------------------------------
		for i, imageTopic in enumerate(self.imageTopics):
			if imageTopic == topic:
				self.imageTopicLB.SetSelection(i)

	# -------------------------------
	def displayProgress(self, i, tot):
	# -------------------------------
		self.frameText.SetLabel('  (%i/%i)  ' % (i, tot))
